package com.hanbitexam.dao;

import java.io.Reader;
import java.util.List;

import com.hanbitexam.vo.CategoryVo;
import com.hanbitexam.vo.QuestionVo;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class CategoryDao {
	private static SqlMapClient sqlmapper;
	List<QuestionVo> list;
	static{
		try{			
			
			Reader reader = Resources.getResourceAsReader("com/hanbitexam/sqlMap/sqlMapConfig.xml");
			sqlmapper = SqlMapClientBuilder.buildSqlMapClient(reader);
			reader.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public static List selectAllCategory() throws Exception{
		return sqlmapper.queryForList("selectAllCategory");
	}
	
	public static List selectCategory(String category) throws Exception{

		//category=toDB(category);
		System.out.println("CategoryDao안 : "+category);
		return sqlmapper.queryForList("selectCategory",category);
	}
	
	public static void deleteCategory(int idx) throws Exception{
		sqlmapper.delete("deleteCategory",idx);
	}
	
	public static void insertCategory(String category) throws Exception{		
		sqlmapper.insert("insertCategory", category);
	}
	
	public static List selectCategoryByIdx(int idx) throws Exception{

		return sqlmapper.queryForList("selectCategoryByIdx",idx);
	}	
	
	public static String toDB(String str)throws Exception{
		String temp;
		temp = new String(str.getBytes("8859_1"),"utf-8");
		//System.out.println(temp);
		return temp;
		
}	
	
}